package datasv.courseProduce_datasv;

import data.datafactory.DatabaseOperator;
import po.CoursePublishPO;

public class GetCousePublish {
	public static void main(String[] args) {
		System.out.println(new GetCousePublish().getCoursePublish("00101130110"));
	}
	public CoursePublishPO getCoursePublish(String courseID){
		return getInSql(courseID);
	}
	private CoursePublishPO getInSql(String courseID){
		String collegeID = courseID.substring(0, 3);
		DatabaseOperator op = new DatabaseOperator("college" + collegeID);
		if (!op.ifDatabaseExist() || !op.ifIDExist("course_list", courseID)) {
			return null;
		}
		int columnNum = AddCoursePublish.columnNum;
		String[] columnName = AddCoursePublish.columnName;
		String[] result = new String[columnNum];
		for (int i = 0; i < columnName.length; i++) {
			String m = op.getOneInform(courseID, "course_list", columnName[i]);
			try {
				m.equals(null);
				//System.out.println(columnName[i] + " is " + m);
			} catch (NullPointerException e) {
				//System.out.println(columnName[i] + " is " + m);
			}
			//System.out.println(columnName[i] + " : " + m);
			result[i] = m;
		}
//		if(!ifAllNull(result)){
//			return null;
//		}
		result[1]=op.getOneInform(result[1],"teacher_list","name");
		return new CoursePublishPO(courseID,result[1],result[2],result[3]);
	}
	
	
	private boolean ifAllNull(String[] m){
		for (int i = 0; i < m.length; i++) {
			try{
				m.equals(null);
			}catch(NullPointerException e){
				return false;
			}
		}
		return true;
	}
}
